import django.utils.timezone as timezone
from aiofiles.os import access
from django.db import models


class BaseModel(models.Model):
    """
    基础模型，包含创建时间和更新时间字段
    """
    is_delete = models.IntegerField("数据逻辑状态", choices=((1, "无效"), (0, "有效")), default=0)
    pt_flag = models.IntegerField("压测标志", choices=((1, "压测数据"), (0, "正常数据")), default=0)
    create_time = models.DateTimeField("创建时间", default=timezone.now)
    update_time = models.DateTimeField("更新时间", auto_now=True, null=True, blank=True)

    class Meta:
        abstract = True  # 表示这是一个抽象类，不会生成对应的表
        ordering = ['-create_time']


class BaseSortModel(BaseModel):
    sort_num = models.SmallIntegerField("排序号", default=0)
    CHOICES_STATUS = ((0, "关闭"), (1, "开启"))
    is_active = models.SmallIntegerField("状态", choices=CHOICES_STATUS, default=1)

    class Meta:
        abstract = True
        ordering = ["-create_time"]


class DingTalkConfig(BaseSortModel):
    """钉钉机器人配置模型"""
    name = models.CharField('配置名称', max_length=100)
    access_token = models.CharField('Token', max_length=255)
    secret = models.CharField('加签密钥', max_length=255)
    description = models.TextField('描述说明', blank=True, default="", help_text="模板的详细用途说明")

    class Meta:
        db_table = 'dingtalk_config'
        verbose_name = '钉钉配置'
        ordering = ['-create_time']
        verbose_name_plural = verbose_name

    def __str__(self):
        return f'name={self.name},access_token={self.access_token},secret={self.secret}'
